package lab.gene.action;

import java.util.Date;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lab.gene.service.impl.GenePCRServiceImpl;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.opensymphony.xwork2.ActionSupport;

public class UpdateGenePCRAction extends ActionSupport implements ServletResponseAware, ServletRequestAware{

	private static final long serialVersionUID = 1L;
	private String geneName = null;
	private Integer sizeOne = 0;
	private String amplicon = null;
	private Date recordDate = null;
	private String comment = null;
	private String username = null;
	private Date datedModified = null;
	private String pcrType = null;
	private String stepType = null;
	
	protected HttpServletResponse servletResponse;  
	@Override   
	public void setServletResponse(HttpServletResponse servletResponse) {   
		this.servletResponse = servletResponse;   
	}   
	
	protected HttpServletRequest servletRequest;   
	@Override   
	public void setServletRequest(HttpServletRequest servletRequest) {   
		this.servletRequest = servletRequest;   
	}
	
	public String execute() {
		//get username from cookie
		Cookie[] cookies = servletRequest.getCookies();
		String cookieName = "LabUser";
		if (cookies != null) {
			for (int i = 0; i < cookies.length; i++) {
				if (cookies[i].getName().equals(cookieName)) {
					username = cookies[i].getValue();
					break;
				}
			}
		}
		System.out.println("UPDATE PCR");
		System.out.println(geneName);
		//check if exist PCR for this gene
		GenePCRServiceImpl service = new GenePCRServiceImpl();
		service.addGenePCR(geneName, username, amplicon, sizeOne, pcrType, comment, recordDate, stepType);

		return "success";
	}
	
	public String getGeneName() {
		return geneName;
	}
	public void setGeneName(String geneName) {
		this.geneName = geneName;
	}

	public Integer getSizeOne() {
		return sizeOne;
	}

	public void setSizeOne(Integer sizeOne) {
		this.sizeOne = sizeOne;
	}

	public String getAmplicon() {
		return amplicon;
	}

	public void setAmplicon(String amplicon) {
		this.amplicon = amplicon;
	}

	public Date getRecordDate() {
		return recordDate;
	}

	public void setRecordDate(Date recordDate) {
		this.recordDate = recordDate;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public Date getDatedModified() {
		return datedModified;
	}

	public void setDatedModified(Date datedModified) {
		this.datedModified = datedModified;
	}

	public String getPcrType() {
		return pcrType;
	}

	public void setPcrType(String pcrType) {
		this.pcrType = pcrType;
	}

	public String getStepType() {
		return stepType;
	}

	public void setStepType(String stepType) {
		this.stepType = stepType;
	} 
}
